
/*
 * xxx.java
 *
 * Created on 12/06/2009, 16:53:35
 * Copyright Guilherme dfg
 */
package Soligee.view;

import Soligee.controller.facade.sessionFacadeImplements.SessionFacadeBuscarImplements;
import Soligee.controller.facade.sessionFacadeImplements.SessionFacadeCadastrarImplements;
import Soligee.decorador.DecoradorInicializaCombos;
import Soligee.decorador.ValidaCamposObrigatorios;
import Soligee.decorador.ValidaCpf;
import Soligee.model.vo.cadastros.PessoaFisicaVO;
import Soligee.view.ApplicationBean1;
import com.icesoft.faces.component.ext.HtmlCommandButton;
import com.icesoft.faces.component.ext.HtmlCommandLink;
import com.icesoft.faces.component.ext.HtmlInputText;
import com.icesoft.faces.component.ext.HtmlInputTextarea;
import com.icesoft.faces.component.ext.HtmlOutputText;
import com.icesoft.faces.component.ext.HtmlPanelGrid;
import com.icesoft.faces.component.ext.HtmlPanelGroup;
import com.icesoft.faces.component.ext.HtmlSelectOneMenu;
import com.icesoft.faces.component.ext.HtmlSelectOneRadio;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectedData;
import com.icesoft.faces.component.jsfcl.data.DefaultSelectionItems;
import com.icesoft.faces.component.jsfcl.data.PopupBean;
import com.icesoft.faces.component.jsfcl.data.SelectInputDateBean;
import com.icesoft.faces.component.panelpopup.PanelPopup;
import com.icesoft.faces.component.paneltabset.PanelTab;
import com.icesoft.faces.component.paneltabset.PanelTabSet;
import com.icesoft.faces.component.selectinputdate.SelectInputDate;
import com.sun.rave.faces.converter.SqlDateConverter;
import com.sun.rave.web.ui.appbase.AbstractPageBean;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.FacesException;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

public class CadastrarPessoaFisica extends AbstractPageBean {
   // <editor-fold defaultstate="collapsed" desc="Managed Component Definition">

   private int __placeholder;
   private static int aux = 0;
   private int controle = 0;
   ValidaCamposObrigatorios valida = new ValidaCamposObrigatorios();

   /**
    * <p>Automatically managed component initialization.  <strong>WARNING:</strong>
    * This method is automatically generated, so any user-specified code inserted
    * here is subject to being replaced.</p>
    */
   private void _init() throws Exception {
   }
   private SelectInputDateBean selectInputDate1Bean = new SelectInputDateBean();

   public SelectInputDateBean getSelectInputDate1Bean() {
      return selectInputDate1Bean;
   }

   public void setSelectInputDate1Bean(SelectInputDateBean sidb) {
      this.selectInputDate1Bean = sidb;
   }
   private SelectInputDateBean selectInputDateBean2 = new SelectInputDateBean();

   public SelectInputDateBean getSelectInputDateBean2() {
      return selectInputDateBean2;
   }

   public void setSelectInputDateBean2(SelectInputDateBean sidb) {
      this.selectInputDateBean2 = sidb;
   }

   //Tipo Endereço
   private DefaultSelectedData botaoSelecionadoTipoEndereco = new DefaultSelectedData();

   public DefaultSelectedData getBotaoSelecionadoTipoEndereco() {
      return botaoSelecionadoTipoEndereco;
   }

   public void setBotaoSelecionadoTipoEndereco(DefaultSelectedData dsd) {
      this.botaoSelecionadoTipoEndereco = dsd;
   }
   private DefaultSelectionItems botaoTipoEndereco = new DefaultSelectionItems();

   public DefaultSelectionItems getBotaoTipoEndereco() {
      return botaoTipoEndereco;
   }

   public void setBotaoTipoEndereco(DefaultSelectionItems dsi) {
      this.botaoTipoEndereco = dsi;
   }
   //Fim-Tipo Endereço

   //UF
   private DefaultSelectedData botaoSelecionadoUf = new DefaultSelectedData();

   public DefaultSelectedData getBotaoSelecionadoUf() {
      return botaoSelecionadoUf;
   }

   public void setBotaoSelecionadoUf(DefaultSelectedData dsd) {
      this.botaoSelecionadoUf = dsd;
   }
   private DefaultSelectionItems botaoUf = new DefaultSelectionItems();

   public DefaultSelectionItems getBotaoUf() {
      return botaoUf;
   }

   public void setBotaoUf(DefaultSelectionItems dsi) {
      this.botaoUf = dsi;
   }

   //Fim-UF

   //Casa Própria
   private DefaultSelectedData botaoSelecionadoCasaPropria = new DefaultSelectedData();

   public DefaultSelectedData getBotaoSelecionadoCasaPropria() {
      return botaoSelecionadoCasaPropria;
   }

   public void setBotaoSelecionadoCasaProprian(DefaultSelectedData dsd) {
      this.botaoSelecionadoCasaPropria = dsd;
   }
   private DefaultSelectionItems botaoCasaPropria = new DefaultSelectionItems();

   public DefaultSelectionItems getBotaoCasaPropria() {
      return botaoCasaPropria;
   }

   public void setBotaoCasaPropria(DefaultSelectionItems dsi) {
      this.botaoCasaPropria = dsi;
   }

   //Fim- Casa Própria
   private DefaultSelectedData botaoSelecionadoSeprocado = new DefaultSelectedData();

   public DefaultSelectedData getBotaoSelecionadoSeprocado() {
      return botaoSelecionadoSeprocado;
   }

   public void setBotaoSelecionadoSeprocadon(DefaultSelectedData dsd) {
      this.botaoSelecionadoSeprocado = dsd;
   }
   private DefaultSelectionItems botaoSeprocado = new DefaultSelectionItems();

   public DefaultSelectionItems getBotaoSeprocado() {
      return botaoSeprocado;
   }

   public void setBotaoSeprocado(DefaultSelectionItems dsi) {
      this.botaoSeprocado = dsi;
   }
   private HtmlCommandLink tx_opCancelarAba01 = new HtmlCommandLink();

   public HtmlCommandLink getTx_opCancelarAba01() {
      return tx_opCancelarAba01;
   }

   public void setTx_opCancelarAba01(HtmlCommandLink hcl) {
      this.tx_opCancelarAba01 = hcl;
   }
   private HtmlCommandLink tx_opCancelarAba02 = new HtmlCommandLink();

   public HtmlCommandLink getTx_opCancelarAba02() {
      return tx_opCancelarAba02;
   }

   public void setTx_opCancelarAba02(HtmlCommandLink hcl) {
      this.tx_opCancelarAba02 = hcl;
   }
   private HtmlCommandLink tx_opCancelarAba03 = new HtmlCommandLink();

   public HtmlCommandLink getTx_opCancelarAba03() {
      return tx_opCancelarAba03;
   }

   public void setTx_opCancelarAba03(HtmlCommandLink hcl) {
      this.tx_opCancelarAba03 = hcl;
   }
   private HtmlInputText campoCodCLiente = new HtmlInputText();

   public HtmlInputText getCampoCodCLiente() {
      return campoCodCLiente;
   }

   public void setCampoCodCLiente(HtmlInputText hit) {
      this.campoCodCLiente = hit;
   }
   private HtmlCommandLink link_proximoPassoAba01 = new HtmlCommandLink();

   public HtmlCommandLink getLink_proximoPassoAba01() {
      return link_proximoPassoAba01;
   }

   public void setLink_proximoPassoAba01(HtmlCommandLink hcl) {
      this.link_proximoPassoAba01 = hcl;
   }
   private PanelTabSet painelCadastrarPessoaFisica = new PanelTabSet();

   public PanelTabSet getPainelCadastrarPessoaFisica() {
      return painelCadastrarPessoaFisica;
   }

   public void setPainelCadastrarPessoaFisica(PanelTabSet pts) {
      this.painelCadastrarPessoaFisica = pts;
   }
   private HtmlCommandLink link_proximoPassoAba02 = new HtmlCommandLink();

   public HtmlCommandLink getLink_proximoPassoAba02() {
      return link_proximoPassoAba02;
   }

   public void setLink_proximoPassoAba02(HtmlCommandLink hcl) {
      this.link_proximoPassoAba02 = hcl;
   }
   private PopupBean panelPopup1Bean = new PopupBean();

   public PopupBean getPanelPopup1Bean() {
      return panelPopup1Bean;
   }

   public void setPanelPopup1Bean(PopupBean pb) {
      this.panelPopup1Bean = pb;
   }
   private PanelPopup panelPopup = new PanelPopup();

   public PanelPopup getPanelPopup() {
      return panelPopup;
   }

   public void setPanelPopup(PanelPopup pp) {
      this.panelPopup = pp;
   }
   private HtmlPanelGrid panelGrid2 = new HtmlPanelGrid();

   public HtmlPanelGrid getPanelGrid2() {
      return panelGrid2;
   }

   public void setPanelGrid2(HtmlPanelGrid hpg) {
      this.panelGrid2 = hpg;
   }
   private HtmlOutputText textoPopUp = new HtmlOutputText();

   public HtmlOutputText getTextoPopUp() {
      return textoPopUp;
   }

   public void setTextoPopUp(HtmlOutputText hot) {
      this.textoPopUp = hot;
   }
   private HtmlSelectOneRadio opcaoCasaPropria = new HtmlSelectOneRadio();

   public HtmlSelectOneRadio getOpcaoCasaPropria() {
      return opcaoCasaPropria;
   }

   public void setOpcaoCasaPropria(HtmlSelectOneRadio hsor) {
      this.opcaoCasaPropria = hsor;
   }
   private HtmlInputText campoNomeCompleto = new HtmlInputText();

   public HtmlInputText getCampoNomeCompleto() {
      return campoNomeCompleto;
   }

   public void setCampoNomeCompleto(HtmlInputText hit) {
      this.campoNomeCompleto = hit;
   }
   private HtmlInputText campoLocalNascimento = new HtmlInputText();

   public HtmlInputText getCampoLocalNascimento() {
      return campoLocalNascimento;
   }

   public void setCampoLocalNascimento(HtmlInputText hit) {
      this.campoLocalNascimento = hit;
   }
   private SelectInputDate dataNascimento = new SelectInputDate();

   public SelectInputDate getDataNascimento() {
      return dataNascimento;
   }

   public void setDataNascimento(SelectInputDate sid) {
      this.dataNascimento = sid;
   }
   private HtmlInputText campoRg = new HtmlInputText();

   public HtmlInputText getCampoRg() {
      return campoRg;
   }

   public void setCampoRg(HtmlInputText hit) {
      this.campoRg = hit;
   }
   private HtmlInputText campoCpf = new HtmlInputText();

   public HtmlInputText getCampoCpf() {
      return campoCpf;
   }

   public void setCampoCpf(HtmlInputText hit) {
      this.campoCpf = hit;
   }
   private SelectInputDate dataCadastro = new SelectInputDate();

   public SelectInputDate getDataCadastro() {
      return dataCadastro;
   }

   public void setDataCadastro(SelectInputDate sid) {
      this.dataCadastro = sid;
   }
   private HtmlInputText campoTelefoneCelular = new HtmlInputText();

   public HtmlInputText getCampoTelefoneCelular() {
      return campoTelefoneCelular;
   }

   public void setCampoTelefoneCelular(HtmlInputText hit) {
      this.campoTelefoneCelular = hit;
   }
   private HtmlInputText campoTelefoneComercial = new HtmlInputText();

   public HtmlInputText getCampoTelefoneComercial() {
      return campoTelefoneComercial;
   }

   public void setCampoTelefoneComercial(HtmlInputText hit) {
      this.campoTelefoneComercial = hit;
   }
   private HtmlInputText campoTelefoneResidencial = new HtmlInputText();

   public HtmlInputText getCampoTelefoneResidencial() {
      return campoTelefoneResidencial;
   }

   public void setCampoTelefoneResidencial(HtmlInputText hit) {
      this.campoTelefoneResidencial = hit;
   }
   private HtmlPanelGroup painelPrincipal = new HtmlPanelGroup();

   public HtmlPanelGroup getPainelPrincipal() {
      return painelPrincipal;
   }

   public void setPainelPrincipal(HtmlPanelGroup hpg) {
      this.painelPrincipal = hpg;
   }
   private HtmlInputText campoPaginaWeb = new HtmlInputText();

   public HtmlInputText getCampoPaginaWeb() {
      return campoPaginaWeb;
   }

   public void setCampoPaginaWeb(HtmlInputText hit) {
      this.campoPaginaWeb = hit;
   }
   private HtmlInputTextarea txarea_observacoes = new HtmlInputTextarea();

   public HtmlInputTextarea getTxarea_observacoes() {
      return txarea_observacoes;
   }

   public void setTxarea_observacoes(HtmlInputTextarea hit) {
      this.txarea_observacoes = hit;
   }
   private HtmlInputTextarea txarea_referencias = new HtmlInputTextarea();

   public HtmlInputTextarea getTxarea_referencias() {
      return txarea_referencias;
   }

   public void setTxarea_referencias(HtmlInputTextarea hit) {
      this.txarea_referencias = hit;
   }
   private HtmlInputText campoLocalTrabalho = new HtmlInputText();

   public HtmlInputText getCampoLocalTrabalho() {
      return campoLocalTrabalho;
   }

   public void setCampoLocalTrabalho(HtmlInputText hit) {
      this.campoLocalTrabalho = hit;
   }
   private HtmlInputText campoSalario = new HtmlInputText();

   public HtmlInputText getCampoSalario() {
      return campoSalario;
   }

   public void setCampoSalario(HtmlInputText hit) {
      this.campoSalario = hit;
   }
   private HtmlInputText campoRua = new HtmlInputText();

   public HtmlInputText getCampoRua() {
      return campoRua;
   }

   public void setCampoRua(HtmlInputText hit) {
      this.campoRua = hit;
   }
   private HtmlInputText campoBairro = new HtmlInputText();

   public HtmlInputText getCampoBairro() {
      return campoBairro;
   }

   public void setCampoBairro(HtmlInputText hit) {
      this.campoBairro = hit;
   }
   private HtmlInputText campoCep = new HtmlInputText();

   public HtmlInputText getCampoCep() {
      return campoCep;
   }

   public void setCampoCep(HtmlInputText hit) {
      this.campoCep = hit;
   }
   private HtmlInputText campoNumero = new HtmlInputText();

   public HtmlInputText getCampoNumero() {
      return campoNumero;
   }

   public void setCampoNumero(HtmlInputText hit) {
      this.campoNumero = hit;
   }
   private HtmlInputText campoComplemento = new HtmlInputText();

   public HtmlInputText getCampoComplemento() {
      return campoComplemento;
   }

   public void setCampoComplemento(HtmlInputText hit) {
      this.campoComplemento = hit;
   }
   private HtmlSelectOneMenu ufPessoaFisica = new HtmlSelectOneMenu();

   public HtmlSelectOneMenu getUfPessoaFisica() {
      return ufPessoaFisica;
   }

   public void setUfPessoaFisica(HtmlSelectOneMenu hsom) {
      this.ufPessoaFisica = hsom;
   }
   private HtmlSelectOneRadio opcaoSeprocado = new HtmlSelectOneRadio();

   public HtmlSelectOneRadio getOpcaoSeprocado() {
      return opcaoSeprocado;
   }

   public void setOpcaoSeprocado(HtmlSelectOneRadio hsor) {
      this.opcaoSeprocado = hsor;
   }
   private HtmlSelectOneRadio tipoEndereco = new HtmlSelectOneRadio();

   public HtmlSelectOneRadio getTipoEndereco() {
      return tipoEndereco;
   }

   public void setTipoEndereco(HtmlSelectOneRadio hsor) {
      this.tipoEndereco = hsor;
   }
   private HtmlInputText campoEmail = new HtmlInputText();

   public HtmlInputText getCampoEmail() {
      return campoEmail;
   }

   public void setCampoEmail(HtmlInputText hit) {
      this.campoEmail = hit;
   }
   private HtmlCommandButton btnPopUp1 = new HtmlCommandButton();

   public HtmlCommandButton getBtnPopUp1() {
      return btnPopUp1;
   }

   public void setBtnPopUp1(HtmlCommandButton hcb) {
      this.btnPopUp1 = hcb;
   }
   private HtmlCommandButton btnPopUp2 = new HtmlCommandButton();

   public HtmlCommandButton getBtnPopUp2() {
      return btnPopUp2;
   }

   public void setBtnPopUp2(HtmlCommandButton hcb) {
      this.btnPopUp2 = hcb;
   }
   private HtmlCommandButton button1 = new HtmlCommandButton();

   public HtmlCommandButton getButton1() {
      return button1;
   }

   public void setButton1(HtmlCommandButton hcb) {
      this.button1 = hcb;
   }
   private DefaultSelectedData selectOneMenu1Bean = new DefaultSelectedData();

   public DefaultSelectedData getSelectOneMenu1Bean() {
      return selectOneMenu1Bean;
   }

   public void setSelectOneMenu1Bean(DefaultSelectedData dsd) {
      this.selectOneMenu1Bean = dsd;
   }
   private DefaultSelectionItems selectOneMenu1DefaultItems = new DefaultSelectionItems();

   public DefaultSelectionItems getSelectOneMenu1DefaultItems() {
      return selectOneMenu1DefaultItems;
   }

   public void setSelectOneMenu1DefaultItems(DefaultSelectionItems dsi) {
      this.selectOneMenu1DefaultItems = dsi;
   }
   private HtmlSelectOneMenu campoCidade = new HtmlSelectOneMenu();

   public HtmlSelectOneMenu getCampoCidade() {
      return campoCidade;
   }

   public void setCampoCidade(HtmlSelectOneMenu hsom) {
      this.campoCidade = hsom;
   }
   private HtmlCommandButton btn_cadastrar = new HtmlCommandButton();

   public HtmlCommandButton getBtn_cadastrar() {
      return btn_cadastrar;
   }

   public void setBtn_cadastrar(HtmlCommandButton hcb) {
      this.btn_cadastrar = hcb;
   }
   private HtmlCommandButton btnConfirmaCadastro = new HtmlCommandButton();

   public HtmlCommandButton getBtnConfirmaCadastro() {
      return btnConfirmaCadastro;
   }

   public void setBtnConfirmaCadastro(HtmlCommandButton hcb) {
      this.btnConfirmaCadastro = hcb;
   }
   private HtmlCommandButton btnPopUp3 = new HtmlCommandButton();

   public HtmlCommandButton getBtnPopUp3() {
      return btnPopUp3;
   }

   public void setBtnPopUp3(HtmlCommandButton hcb) {
      this.btnPopUp3 = hcb;
   }
   private PanelTab aba01 = new PanelTab();

   public PanelTab getAba01() {
      return aba01;
   }

   public void setAba01(PanelTab pt) {
      this.aba01 = pt;
   }
   private PanelTab aba02 = new PanelTab();

   public PanelTab getAba02() {
      return aba02;
   }

   public void setAba02(PanelTab pt) {
      this.aba02 = pt;
   }
   private PanelTab aba03 = new PanelTab();

   public PanelTab getAba03() {
      return aba03;
   }

   public void setAba03(PanelTab pt) {
      this.aba03 = pt;
   }
    private SqlDateConverter sqlDateConverter1 = new SqlDateConverter();

    public SqlDateConverter getSqlDateConverter1() {
        return sqlDateConverter1;
    }

    public void setSqlDateConverter1(SqlDateConverter sdc) {
        this.sqlDateConverter1 = sdc;
    }


   // </editor-fold>
   public CadastrarPessoaFisica() {
   }

   @Override
   public void init() {
      super.init();
      limparCampos();
      this.inicializarCampos();



      // <editor-fold defaultstate="collapsed" desc="Managed Component Initialization">
      // Initialize automatically managed components
      // *Note* - this logic should NOT be modified
      try {
         _init();
      } catch (Exception e) {
         log("xxx Initialization Failure", e);
         throw e instanceof FacesException ? (FacesException) e : new FacesException(e);
      }

   // </editor-fold>
   }

   
   public void inicializarCampos() {
      //mostra o valor do id correto para inserção no banco
      campoNomeCompleto.setMaxlength(100);
      campoRg.setMaxlength(10);
      campoLocalTrabalho.setMaxlength(50);
      campoLocalNascimento.setMaxlength(30);
      campoRua.setMaxlength(50);
      campoComplemento.setMaxlength(50);
      campoBairro.setMaxlength(50);
      campoNumero.setMaxlength(10);
      campoLocalTrabalho.setMaxlength(50);
      campoPaginaWeb.setMaxlength(50);
      campoEmail.setMaxlength(50);
      campoSalario.setMaxlength(7);
      //inicializao de campo de codigo de Pessoa Fisica
      try {
        SessionFacadeBuscarImplements facadeBusca = new SessionFacadeBuscarImplements();
        List<PessoaFisicaVO> listaPessoas = facadeBusca.buscarTodos("codPessoa", PessoaFisicaVO.class);
        int tamanholista = listaPessoas.size();
        PessoaFisicaVO pessoa;
        pessoa = listaPessoas.get(tamanholista-1);
        int proximocodigo = pessoa.getCodPessoa()+1;

        campoCodCLiente.setValue(proximocodigo);
      } catch (Exception e) {
         System.err.println(e.getMessage());
      }

      //UF
      botaoUf.clear();
      botaoUf.add(new SelectItem(1, "AC"));
      botaoUf.add(new SelectItem(2, "AL"));
      botaoUf.add(new SelectItem(3, "AP"));
      botaoUf.add(new SelectItem(4, "AM"));
      botaoUf.add(new SelectItem(5, "BA"));
      botaoUf.add(new SelectItem(6, "CE"));
      botaoUf.add(new SelectItem(7, "DF"));
      botaoUf.add(new SelectItem(8, "ES"));
      botaoUf.add(new SelectItem(9, "GO"));
      botaoUf.add(new SelectItem(10, "MA"));
      botaoUf.add(new SelectItem(11, "MT"));
      botaoUf.add(new SelectItem(12, "MS"));
      botaoUf.add(new SelectItem(13, "MG"));
      botaoUf.add(new SelectItem(14, "PA"));
      botaoUf.add(new SelectItem(15, "PB"));
      botaoUf.add(new SelectItem(16, "PR"));
      botaoUf.add(new SelectItem(17, "PE"));
      botaoUf.add(new SelectItem(18, "PI"));
      botaoUf.add(new SelectItem(19, "RJ"));
      botaoUf.add(new SelectItem(20, "RN"));
      botaoUf.add(new SelectItem(21, "RS"));
      botaoUf.add(new SelectItem(22, "RO"));
      botaoUf.add(new SelectItem(23, "RR"));
      botaoUf.add(new SelectItem(24, "SC"));
      botaoUf.add(new SelectItem(25, "SP"));
      botaoUf.add(new SelectItem(26, "SE"));
      botaoUf.add(new SelectItem(27, "TO"));

      //controla a exibição da pop up
      panelPopup.setRendered(false);
      campoCodCLiente.setReadonly(true);

      //Tipo Endereço
      botaoTipoEndereco.clear();
      botaoTipoEndereco.add(new SelectItem(1, "Residencial"));
      botaoTipoEndereco.add(new SelectItem(2, "Comercial"));

      //Casa Própria
      botaoCasaPropria.clear();
      botaoCasaPropria.add(new SelectItem(1, "Sim"));
      botaoCasaPropria.add(new SelectItem(2, "Nao"));

      //Seprocado
      botaoSeprocado.clear();
      botaoSeprocado.add(new SelectItem(1, "Sim"));
      botaoSeprocado.add(new SelectItem(2, "Nao"));

      tipoEndereco.setValue(new Integer(1));
      opcaoSeprocado.setValue(new Integer(1));
      opcaoCasaPropria.setValue(new Integer(1));

      painelCadastrarPessoaFisica.setSelectedIndex(0);

      InicializaCampoCidade(16);
      ufPessoaFisica.setValue(16);
      campoCidade.setValue(2788);
      btnPopUp3.setRendered(false);

      //InicializarAbas
      aba01.setDisabled(false);
      aba02.setDisabled(true);
      aba03.setDisabled(true);

      //inicializa data de nascimento
      Date data = new Date(1960-1900, 0,1);
      dataNascimento.setValue(data);     

  
   }

   public void tx_opCancelarAba_action() {
      this.limparCampos();
      this.inicializarCampos();
   }

   public String link_proximoPassoAba01_action() {
      Date datanascimento = (Date) (Object) dataNascimento.getValue();
      Date datacadastro = (Date) (Object) dataCadastro.getValue();

      valida.verificaCampoVazio(campoNomeCompleto);
      valida.verificaCampoVazio(campoCpf);
      valida.verificaCampoVazio(campoRg);
       if (datanascimento.before(datacadastro)) {

         painelCadastrarPessoaFisica.setSelectedIndex(1);
         aba01.setDisabled(true);
         aba02.setDisabled(false);
         aba03.setDisabled(true);

      } else {

         controlaPopup(true, "Data Nascimento deve ser Anterior ao Cadastro", false, true, "", "OK");
      }
      return null;
   }

   public String link_proximoPassoAba02_action() {
      valida.verificaCampoVazio(campoRua);
      valida.verificaCampoVazio(campoNumero);
      valida.verificaCampoVazio(campoBairro);
      valida.verificaCampoVazio(campoCep);

         painelCadastrarPessoaFisica.setSelectedIndex(2);
         aba01.setDisabled(true);
         aba02.setDisabled(true);
         aba03.setDisabled(false);
      
      return null;
   }

   public double parserDouble(Object o) {
      return Double.parseDouble(o.toString());
   }

   public int parserInt(Object o) {
      return Integer.parseInt(o.toString());
   }

   public String btn_cadastrar_action() {
       if (valida.verificaCampoVazio(campoNomeCompleto) || valida.verificaCampoVazio(campoCpf) || valida.verificaCampoVazio(campoRg)) {
           painelCadastrarPessoaFisica.setSelectedIndex(0);
           aba01.setDisabled(false);
           aba02.setDisabled(true);
           aba03.setDisabled(true);
           controlaPopup(true, "Campos Obrigatórios!", false, true, "", "OK");
      }

       else if (valida.verificaCampoVazio(campoRua) || valida.verificaCampoVazio(campoNumero) ||
              valida.verificaCampoVazio(campoBairro) || valida.verificaCampoVazio(campoCep)) {
           painelCadastrarPessoaFisica.setSelectedIndex(1);
           aba01.setDisabled(true);
           aba02.setDisabled(false);
           aba03.setDisabled(true);
           controlaPopup(true, "Campos Obrigatórios!", false, true, "", "OK");
      }
      else if (valida.verificaCampoVazio(campoSalario)) {
           painelCadastrarPessoaFisica.setSelectedIndex(1);
           aba01.setDisabled(true);
           aba02.setDisabled(true);
           aba03.setDisabled(false);
           controlaPopup(true, "Campos Obrigatórios!", false, true, "", "OK");
      }
      else
          controlaPopup(true, "Deseja cadastar Cliente Fisico?", true, true, "Sim", "Não");
          aux = 5;
      return null;
   }

   public String btnPopUp2_action() {
       if(aux==1){
           panelPopup.setRendered(false);
           return "";
       }
       else
      panelPopup.setRendered(false);

      return null;
   }

   public void controlaPopup(boolean renderedPopup, String textoPoup, boolean btn1Rendered, boolean btn2Rendered,
           String textobtn1, String textobtn2) {

      panelPopup.setRendered(renderedPopup);
      textoPopUp.setValue(textoPoup);
      btnConfirmaCadastro.setValue(textobtn1);
      btnConfirmaCadastro.setRendered(btn1Rendered);
      btnPopUp2.setRendered(btn2Rendered);
      btnPopUp2.setValue(textobtn2);
   }

   //metodo para preenchimento do combobox fornecedor
   public void InicializaCampoCidade(int codEstado) {
      this.setSelectOneMenu1DefaultItems(new DecoradorInicializaCombos().inicializaCampoCidade(codEstado));
   }

   public void limparCampos() {
      FacesContext.getCurrentInstance().getExternalContext().getRequestMap().clear();
      campoNomeCompleto.resetValue();
      dataNascimento.resetValue();
      campoLocalNascimento.resetValue();
      dataCadastro.resetValue();
      campoRg.resetValue();
      campoCpf.resetValue();
      campoTelefoneResidencial.resetValue();
      campoTelefoneCelular.resetValue();
      campoTelefoneComercial.resetValue();
      campoRua.resetValue();
      campoNumero.resetValue();
      campoComplemento.resetValue();
      campoBairro.resetValue();
      campoCep.resetValue();
      campoCidade.resetValue();
      ufPessoaFisica.resetValue();
      campoLocalTrabalho.resetValue();
      campoSalario.resetValue();
      tipoEndereco.setValue(new Integer(1));
      opcaoSeprocado.setValue(new Integer(1));
      opcaoCasaPropria.setValue(new Integer(1));
      campoPaginaWeb.resetValue();
      campoEmail.resetValue();
      txarea_referencias.resetValue();
      txarea_observacoes.resetValue();
      painelCadastrarPessoaFisica.setSelectedIndex(0);

   }

   @Override
   public void preprocess() {
   }

   @Override
   public void prerender() {
   }

   @Override
   public void destroy() {
   }

   protected ApplicationBean1 getApplicationBean1() {
      return (ApplicationBean1) getBean("ApplicationBean1");
   }

   protected RequestBean1 getview$RequestBean1() {
      return (RequestBean1) getBean("view$RequestBean1");
   }

   protected SessionBean1 getview$SessionBean1() {
      return (SessionBean1) getBean("view$SessionBean1");
   }

   protected ApplicationBean1 getview$ApplicationBean1() {
      return (ApplicationBean1) getBean("view$ApplicationBean1");
   }

   public void ufPessoaFisica_processValueChange(ValueChangeEvent vce) {
      InicializaCampoCidade(Integer.parseInt(ufPessoaFisica.getValue().toString()));
   }

   public String btnConfirmaCadastro_action() {

      if (controle == 0) {
         SessionFacadeCadastrarImplements cadastrar = new SessionFacadeCadastrarImplements();
         Date datanascimento = (Date) (Object) dataNascimento.getValue();
         Date datacadastro = (Date) (Object) dataCadastro.getValue();

         try {
            if (cadastrar.cadastrarPessoaFisica(this.parserInt(opcaoCasaPropria.getValue()), this.parserInt(campoCodCLiente.getValue()),
                    campoNomeCompleto.getValue().toString(), campoTelefoneResidencial.getValue().toString(),
                    campoTelefoneCelular.getValue().toString(), campoTelefoneComercial.getValue().toString(), datanascimento,
                    campoRg.getValue().toString(), campoEmail.getValue().toString(), campoPaginaWeb.getValue().toString(),
                    txarea_referencias.getValue().toString(), campoCpf.getValue().toString(), "", datacadastro,
                    txarea_observacoes.getValue().toString(), campoLocalTrabalho.getValue().toString(),
                    this.parserDouble(campoSalario.getValue()), this.parserInt(opcaoSeprocado.getValue()), campoLocalNascimento.getValue().toString(),
                    1, this.parserInt(tipoEndereco.getValue()), campoRua.getValue().toString(), campoBairro.getValue().toString(), campoCep.getValue().toString(),
                    campoNumero.getValue().toString(), campoComplemento.getValue().toString(), this.parserInt(ufPessoaFisica.getValue()))) {
               controlaPopup(true, "Pessoa Física Cadastrada com Sucesso!", false, true, "", "OK");
               limparCampos();
               painelCadastrarPessoaFisica.setSelectedIndex(0);
               aux = 1;


            }
         } catch (IOException ex) {
            controlaPopup(true, "Erro:" + ex.getMessage() + "caused by: " + ex.getStackTrace(), false, true, "", "OK");
            System.err.println("Erro:" + ex.getMessage() + "caused by: " + ex.getStackTrace());
            aux = 1;
         } catch (Exception e) {
            controlaPopup(true, "Erro:" + e.getMessage() + "caused by: " + e.getStackTrace(), false, true, "", "OK");
            System.err.println("Erro:" + e.getMessage() + "caused by: " + e.getStackTrace());
            aux = 1;
         }

         System.out.println("botao do cadastro");
         return null;
      } else if (controle == 1) {
         panelPopup.setRendered(false);
         return "voltar";
      }
      return null;

   }

   public String link_AbaAnterior01_action() {
      valida.verificaCampoVazio(campoRua);
      valida.verificaCampoVazio(campoNumero);
      valida.verificaCampoVazio(campoBairro);
      valida.verificaCampoVazio(campoCep);
      painelCadastrarPessoaFisica.setSelectedIndex(0);
      aba01.setDisabled(false);
      aba02.setDisabled(true);
      aba03.setDisabled(true);
      return null;
   }

   public String link_AbaAnterior02_action() {
      valida.verificaCampoVazio(campoSalario);
      painelCadastrarPessoaFisica.setSelectedIndex(1);
      aba01.setDisabled(true);
      aba02.setDisabled(false);
      aba03.setDisabled(true);
      return null;
   }


   //botaoVoltarSuperior
   public String btn_voltar_action() {
      controle = 1;
      controlaPopup(true, "Deseja Sair ?", true, true, "Sim", "Não");
      System.out.println(controle);
      return null;
   }

   public void validateCampoUnico(FacesContext context, UIComponent component, Object value) {
      try {
         new ValidaCpf().validateCampoUnico(context, component, value);
      }catch(Exception e){
         //controlaPopup(true, e.getMessage(), false, true, "", "OK");
      }
   }
}
